package mo.offer_special;

public class L002 {

    public String addBinary(String a, String b) {
        StringBuilder builder = new StringBuilder();
        int i = 0;
        int carry = 0;
        int lengthA = a.length();
        int lengthB = b.length();
        while (i < lengthA || i < lengthB) {
            int num1 = 0;
            if (i < lengthA) {
                num1 = a.charAt(lengthA-1-i) - '0';
            }
            int num2 = 0;
            if (i < lengthB) {
                num2 = b.charAt(lengthB-1-i) - '0';
            }
            builder.append((num1+num2+carry) % 2);
            carry = (num1+num2+carry) / 2;
            i++;
        }
        if (carry == 1) {
            builder.append(carry);
        }
        return builder.reverse().toString();
    }

    public static void main(String[] args) {
        L002 test = new L002();
        System.out.println(test.addBinary("11", "10"));
    }
}
